from django.db import models
from xtversion.models import ProjectManage
from django.contrib.auth.models import User
from utils.datetimeutil import set_next_date_time


class AttendanceManage(models.Model):
    # 项目， 申请人， 申请工号，
    weekdays = (
        ('Sat', '周六'),
        ('Sun', '周日')
    )
    project = models.ForeignKey(ProjectManage, related_name='att_project', on_delete=models.CASCADE, verbose_name='项目名称')
    applicant = models.ForeignKey(User,  related_name='att_applicant', on_delete=models.CASCADE, verbose_name='申请人')
    hw_headman = models.CharField(max_length=20, default='程代科', verbose_name='华为组长')
    hw_pm = models.CharField(max_length=20, default='程代科', verbose_name='华为PM')
    reason = models.CharField(max_length=500, verbose_name='加班理由')
    start_time = models.DateTimeField(verbose_name='加班开始时间', default=set_next_date_time()[0])
    end_time = models.DateTimeField(verbose_name='加班结束时间', default=set_next_date_time()[1])
    weekday = models.CharField(max_length=10, choices=weekdays, default='Sat', verbose_name='星期')
    creator = models.ForeignKey(User, related_name='att_creator', verbose_name='创建人', on_delete=models.CASCADE)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '加班管理'
        verbose_name_plural = verbose_name
        db_table = 'xt_a_attendance'

    def __str__(self):
        return self.project.project_name
